import { reqGetDetailData } from "@/api"
export default {
  namespaced: true,
  state: {
    detailIntro: {}
  },
  actions: {
    //  发送请求获取详情信息数据
    async GetDetailIntro({ commit }, skuId) {
      let { data, code } = await reqGetDetailData(skuId)

      if (code === 200) {
        commit("SetDetailIntro", data)
      } else {
        console.log("失败了！")
      }
    }
  },
  mutations: {
    // 1.设置详情信息数据
    SetDetailIntro(state, detailIntro) {
      state.detailIntro = detailIntro
    },
    // 2.点击小图实现高亮效果并且切换大图
    SetUpdateImage(state, skuImage) {
      // 2.1先将每一项的状态设为一致 利用排他思想
      state.detailIntro.skuInfo.skuImageList.forEach(item => {
        item.isDefault = "0"
      })
      // 2.2将当前点击的这一项变为高亮
      skuImage.isDefault = "1"
      // 2.3将当前具有高亮效果的小图片切换为大图
      state.detailIntro.skuInfo.skuDefaultImg = skuImage.imgUrl
    }
  },
  getters: {
    // categoryView skuInfo spuSaleAttrList
    categoryView(state) {
      return state.detailIntro.categoryView || {}
    },
    skuInfo(state) {
      return state.detailIntro.skuInfo || {}
    },
    spuSaleAttrList(state) {
      return state.detailIntro.spuSaleAttrList || []
    }
  }
}